home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 102 / examples / ladybug2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-25  |  5.8 KB  |  123 lines

  1. /* Programmer's guide to GEM - 1986 - p.158 -listing 3.2 - CJPurcell Dec'86  */
  2. /* CTRLRC.C  -  MAIN DRIVER for draw_rc()  examples  using Mark Williams C   */
  3. /* to be tested in NDC and/or RC mode with or without GDOS for implications  */
  4. #include <portab.h>                       /* MWC consistant ?? */
  5. #include <osbind.h>                       /* system constants  */
  6. #include <gemdefs.h>                      /* GEM-definition    */
  7. /* #include <obdefs.h>  manually CJP     / * object definition */
  8.  
  9. WORD contrl[12], intin[128], ptsin[128], intout[128], ptsout[128];
  10.  
  11. #define M_OFF 256
  12. #define RC_COORDS 2
  13. #define RIGHT_ALIGNED 2
  14. #define BOTTOM_ALIGNED 3
  15.  
  16. VOID main()                /* not GEMAIN as in ref. */
  17. {
  18.         WORD handle, work_in[11], work_out[57], max_w, max_h;
  19.         WORD ii;
  20.  
  21.         appl_init();                                    /* init AES for call */
  22.         handle = graf_handle( &ii,&ii,&ii,&ii );        /* get screen handle */
  23.         graf_mouse( M_OFF, NULL );                      /* hide mouse        */
  24.         v_clrwk( handle );                              /* clear workstation */
  25.  
  26.         for( ii=0; ii<11; ++ii ) work_in[ii]=1;         /* init work_in array*/
  27.         work_in[10] = RC_COORDS;                     /* using RC coordinates */
  28.         v_opnvwk( work_in, &handle, work_out );      /* open the workstation */
  29.  
  30.         max_w = work_out[0]; max_h = work_out[1];
  31.         draw_rc( handle,0,0,max_w,max_h );           /* do the examp.routine */
  32.  
  33.         vst_alignment( handle,RIGHT_ALIGNED,BOTTOM_ALIGNED,&ii,&ii );
  34.         v_gtext( handle,max_w,max_h,"Press any Key to Continue" );
  35.         evnt_keybd();                                   /* pause for viewing */
  36.         v_clsvwk( handle );                             /* close workstation */
  37.         appl_exit();                                    /* tell AES finished */
  38. }
  39.  
  40. /* ref.p.236/7-Listing 3.23 CPYTRAN2.C - Display 2 live bug images on screen */
  41. #define LEFT          0
  42. #define WHITE         0
  43. #define ADDR        /*?*/                               /* ? as in machine.h */
  44. #define MD_REPLACE    1                                 /* ? as in machine.h */
  45. #define BLACK         1
  46. #define ImageBytes    2                                 /* # bytes in raster */
  47. #define FIS_PATTERN   2
  48. #define MD_XOR        3
  49. #define TOP           5
  50. #define ImageRows     10                                /*   rows            */
  51. #define ImageBitWidth 11                                /* # significant bits*/
  52.  
  53. WORD image1[10] =  { 0x9200,0x4900,0x2480,0x3f80,0x7fd0,
  54.                      0x7fd0,0x3f80,0x2480,0x4900,0x9200 };
  55. WORD image2[10] =  { 0x2480,0x2480,0x2480,0x3f80,0x7fd0,
  56.                      0x7fd0,0x3f80,0x2480,0x2480,0x2480 };
  57. WORD image3[10] =  { 0x0920,0x1240,0x2480,0x3f80,0x7fd0,
  58.                      0x7fd0,0x3f80,0x2480,0x1240,0x0920 };
  59.  
  60. VOID draw_rc( handle, dx, dy, swidth, sheight )
  61.         WORD  handle, dx, dy, swidth, sheight;
  62. {
  63.         FDB  img_m[3], scr_m  ;
  64.         WORD ii, cur_x, cur_y, y_incr, pxy[8], colors[2];
  65.  
  66.         y_incr = sheight / 3;
  67.         cur_y = dy + y_incr;
  68.         vst_alignment( handle, LEFT, TOP, &ii, &ii );
  69.         v_gtext( handle, dx + swidth/2, cur_y,  "This line uses REPLACE MODE");
  70.         v_gtext( handle, dx +swidth/2,cur_y+ y_incr,"This line uses XOR MODE");
  71.  
  72.         pxy[0] = dx + swidth  / 20 ;       /* display backdrop to crawl thru */
  73.         pxy[1] = dy + sheight / 10 ;
  74.         pxy[2] = dx + (swidth / 2) - ( swidth / 20 );
  75.         pxy[3] = dy + sheight      - (sheight / 10 );
  76.  
  77.         vsf_color   ( handle, BLACK  );
  78.         vsf_interior( handle, FIS_PATTERN );
  79.         vsf_style   ( handle, 3  );
  80.         v_rfbox     ( handle, pxy);
  81.                                            /* initialize all 3 FDB's         */
  82.         img_m[0].fd_addr          = ADDR( image1 )  ;
  83.         img_m[1].fd_addr          = ADDR( image2 )  ;
  84.         img_m[2].fd_addr          = ADDR( image3 )  ;
  85.         for( ii = 0 ; ii < 3 ; ++ii )
  86.         {
  87.         img_m[ii].fd_w                        = ImageBytes << 3 ;
  88.         img_m[ii].fd_h                        = ImageRows       ;
  89.         img_m[ii].fd_wdwidth                  = ImageBytes >> 1 ;
  90.         img_m[ii].fd_stand                    = 1               ;
  91.         img_m[ii].fd_nplanes                  = 1               ;
  92.         img_m[ii].fd_r1 = img_m[ii].fd_r2 = img_m[ii].fd_r3 = 0 ;
  93.         vr_trnfm( handle, &img_m[ii], &img_m[ii] ) ; /*  in place transform  */
  94.         }
  95.         scr_m.fd_addr    =    0L ;          /* Screen FDB -> physical device */
  96.         colors[0]  = BLACK  ; colors[1] = WHITE ;     /*  Black and White    */
  97.  
  98.         pxy[0]     = 0 ;
  99.         pxy[1]     = 0 ;
  100.         pxy[2]     = pxy[0] + ImageBitWidth -1 ;
  101.         pxy[3]     = pxy[1] + ImageRows - 1 ;
  102.  
  103.         for( cur_x = dx ; cur_x < (dx + swidth / 2) - ImageBitWidth ; ++cur_x )
  104.         {
  105.                 pxy[4]     = cur_x ;
  106.                 pxy[6]     = pxy[4] + ImageBitWidth ;
  107.                 for ( ii = 0 ; ii < 3 ; ++ ii )
  108.                 {
  109.                      pxy[5]     =  cur_y + y_incr    ;
  110.                      pxy[7]     = pxy[5] + ImageRows ;
  111.                      vrt_cpyfm(handle,MD_XOR,    pxy,&img_m[ii],&scr_m,colors);
  112.                      pxy[5]     =  cur_y             ;
  113.                      pxy[7]     = pxy[5] + ImageRows ;
  114.                      vrt_cpyfm(handle,MD_REPLACE,pxy,&img_m[ii],&scr_m,colors);
  115.                      pxy[5]     =  cur_y + y_incr    ;
  116.                      pxy[7]     = pxy[5] + ImageRows ;
  117.                      vrt_cpyfm(handle,MD_XOR,    pxy,&img_m[ii],&scr_m,colors);
  118.                 }
  119.             }
  120.         /*  display for one last time so as to leave an image on the screen  */
  121.     vrt_cpyfm( handle, MD_XOR, pxy, &img_m[2], &scr_m, colors ) ; /* BITBLT  */
  122. }                                                        /*CJPurcell 08Dec'86*/
  123.